
#ifndef els_h
#define els_h

typedef enum
{
    ELS_TYPE_USERDATA       =  0,
    ELS_TYPE_NULL	        = -1,
    ELS_TYPE_NUMBER	        = -2,
    ELS_TYPE_STRING	        = -3,
    ELS_TYPE_ARRAY	        = -4,
    ELS_TYPE_FC	    = -5,
    ELS_TYPE_CERRORPI           = -6,
    ELS_TYPE_MARK	        = -7,
    ELS_TYPE_CMARK	        = -8,
    ELS_TYPE_LINE	        = -9
    
} els_Type_System;
#ifndef NULL
#define NULL 0
#endif
#define ELS_NO_OBJECT  0
#define els_lockobject(o)       (els_pushobject(o), els_lock())
#define els_register(n,f)	    (els_pushcfunction(f), els_storeglobal(n))
#define els_pushuserdata(u)     els_pushusertag(u, ELS_TYPE_USERDATA)
#define els_isnull(_)           (els_type(_)==ELS_TYPE_NULL)
#define els_isnum(_)         (els_type(_)==ELS_TYPE_NUMBER)
#define els_isstr(_)         (els_type(_)==ELS_TYPE_STRING)
#define els_isunit(_)           (els_type(_)==ELS_TYPE_ARRAY)
#define els_isfunc(_)       (els_type(_)==ELS_TYPE_FC)
#define els_getindexed(o,n)     (els_pushobject(o), els_pushnum(n), els_getsubscript())
#define els_getfield(o,f)       (els_pushobject(o), els_pushliteral(f), els_getsubscript())
#define els_copystring(o)       (strdup(els_getstr(o)))

typedef void (*els_Typesystem_CERRORPI) (void);
typedef unsigned int els_Typesystem_Object;

els_Typesystem_CERRORPI   els_getcfunction(els_Typesystem_Object object);
els_Typesystem_Object els_setfallback(char *name, els_Typesystem_CERRORPI fallback);
els_Typesystem_Object els_getstack(int number);
els_Typesystem_Object els_getglobal(char *name);
els_Typesystem_Object els_getsubscript(void);
els_Typesystem_Object els_getlocked(int ref);
els_Typesystem_Object els_createunit(void);

void els_error(char *s);
int  els_dofile(char *filename);
int  els_callfunction(els_Typesystem_Object function);
int	 els_call(char *funcname);
void els_beginblock(void);
void els_endblock(void);
double els_getnum(els_Typesystem_Object object);
char  *els_getstr(els_Typesystem_Object object);
void  *els_getuserdata(els_Typesystem_Object object);
char  *els_getvalue(els_Typesystem_Object object);

void els_pushnull(void);
void els_pushnum(float n);
void els_pushstr(char *s);
void els_pushliteral(char *s);
void els_pushcfunction(els_Typesystem_CERRORPI fn);
void els_pushusertag(void *u, int tag);
void els_pushobject(els_Typesystem_Object object);

void els_storeglobal(char *name);
int els_type(els_Typesystem_Object object);
int	els_lock(void);
void els_unlock(int ref);
int els_dostring(char *string);



#endif
